package com.monitorRoutine.monitorRoutineServer.task;

import com.monitorRoutine.monitorRoutineServer.service.ProcessService;
import com.monitorRoutine.monitorRoutineServer.util.TimeUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.Duration;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
@Component
@EnableScheduling
@Slf4j
public class MonitoringServiceTask {
    @Autowired
    ProcessService processService;
    @Scheduled(cron = "0 */1 * * * *")
    public void scanProcess(){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
        Instant startTime = Instant.now();
        log.info("进程结果扫描，时间："+ TimeUtil.formatInstant(startTime, formatter));
        processService.sanMonitorProcessResult();
        Instant endTime = Instant.now();
        long executionTime = Duration.between(startTime, endTime).toMillis();
        log.info("进程结果扫描 完成，时间："+TimeUtil.formatInstant(endTime, formatter)+"用时:"+executionTime);
    }
}
